/**
 * Created by mhy on 2018/6/30.
 */
import {post,get,uploadimg} from './request'
import {baseURL} from  './baseURL'

//获取验证码
export function getMobileCode (phone) {
  return post('/api/v1/user/codeid',{
    userphone: phone,
    type: 0,
    nationcode: '86'
  },{})
}

//账号密码登录

export function loginWithPhone(phone,code,codeid) {
  return post('/api/v1/warehouse/platform/login',{
    action: 'login',
    userphone: phone,
    codeid:  codeid,
    code: code,
    deviceid: 'C3B38031-AC78-4C2C-9C4A-469A28C54E60',
    nationcode: '86'
  },{})

}
//微信登录
export  function loginWx(params) {
  return post('/api/v1/warehouse/platform/login',params,{})
}

export  function wxinfo(params) {
  return post('/api/v1/weixin/userinfo',params,{})
}

//用户信息

export  function getUserInfo(userid){
  return post('/api/v1/warehouse/platform',{
    userid: userid,
    action: 'get'
  },{})
}
//框条信息
export function infoFrame(params) {
  return post('/api/v1//warehouse/material/frame',params,{})
}
// //新增框条
// export  function updateFrame(params) {
//   return post('/api/v1//warehouse/material/frame',params,{})
// }
//上传框条库图片
export function uploadFrame(formdata) {
  return uploadimg('/api/v1/warehouse/upload/frame',formdata,{})
}
//上传背景
export function uploadBackgroud(formdata){
  return uploadimg('/api/v1/warehouse/upload/background',formdata,{})
}
//背景操作
export  function infoBackground(params) {
  return post('/api/v1/warehouse/material/background',params,{})
}

export function uploadMatCard(formdata){
  return uploadimg('/api/v1/warehouse/upload/matcard',formdata,{})
}
export function infoMatCard(params) {
  return post('/api/v1/warehouse/material/matcard',params,{})
}

export function uploadSence(formdata){
  return uploadimg('/api/v1/warehouse/upload/scene',formdata,{})
}
export function infoSence(params){
  return post('/api/v1/warehouse/material/scene',params,{})
}
// 厂家上传图片
export function uploadFactoryImage(formdata) {
  return post('/api/v1/warehouse/upload/factory', formdata, {})
}

//新增厂家
export function addNewFactory(params) {
  // info = JSON.stringify(info)
  return post('/api/v1/warehouse/factory', params, {})
}

//新增厂家
export function getFactoryList({page = 1, search = ''}) {
  return post('/api/v1/warehouse/factory', {action: 'getlist', pagesize: 50, page, search}, {
    // token: localStorage.getItem('token')
  })
}

//更新厂家
export function updateFactoryData(params) {
  // info = JSON.stringify(info)
  // info = JSON.stringify(info)
  return post('/api/v1/warehouse/factory', params, {})
}

//得到某一个厂家数据
export function getFactoryData(id) {
  return post('/api/v1/warehouse/factory', {action: 'get', id}, {})
}


//用户
//得到用户列表
export function getUserList(params) {
  return post('/api/v1/warehouse/user', params, {})
}

//得到用户详情
export function getUserDetail(userid) {
  return post('/api/v1/warehouse/user', {action: 'get', userid}, {})
}

//商户
//得到商户列表
export function getShopList({type = null, state = null, page = 1, search = null}) {
  return post('/api/v1/warehouse/user', {action: 'getlist', pagesize: 10, page, search, type, state, viptime: null}, {})
}

//得到商户详情
export function getShopDetail(userid) {
  return post('/api/v1/warehouse/user', {action: 'get', userid}, {})
}

//得到商户购买记录
export function getShopRecord(userid) {
  return post('/api/v1/warehouse/shopowner', {action: 'getbuyrecordlist', userid}, {})
}


export function updateUserDetail(params) {
  return post('/api/v1/warehouse/user', params, {})
}

// 更新商户信息
export function updateShopDetail({userid = null, subid = null, states = null}) {
  return post('/api/v1/warehouse/user', {action: 'updateSubManager', userid, subid, state: states}, {})
}

// 更新商户状态
export function updateShopState(params) {
  return post('/api/v1/warehouse/shopowner', params, {})
}

export function userBuyVip(params) {
  return post('/api/v1/vip/buy', params, {})
}

// 平台用户
// 得到平台用户列表
export function getPlateList({page = 1, search = ''}) {
  return post('/api/v1/warehouse/platform', {action: 'getlist', pagesize: 10, page, search}, {})
}

// 得到平台用户详情
export function getPlateDetail(userid) {
  return post('/api/v1/warehouse/platform', {action: 'get', userid}, {})
}

// 生成动态二维码开通子管理员
export function addSubManager(params) {
  return post('/api/v1/warehouse/platform', params, {})
}

// 得到用户VIP记录
export function getVipRecordList(userid) {
  return post('/api/v1/user/vip/recordlist', {userid}, {})
}

// 得到用户邀请记录
export function getInviteRecordList({userid, page = 1}) {
  return post('/api/v1/warehouse/user', {action: 'getinviterecordlist', userid, pagesize: 10, page}, {})
}

// 更新子管理员信息
export function changeSubMangerInfo({userid, states, auth = 'frame#platform#', duty = 'duty', comment = '助手'}) {
  return post('/api/v1/warehouse/platform', {action: 'update', userid, state: states, auth, duty, comment}, {})
}

// 更新子管理员的状态
export function updateSubManagerState({userid, states, subid}) {
  return post('/api/v1/warehouse/platform', {action: 'update', userid, state: states, subid}, {})
}
